//
//  ViewController.m
//  MonitorKitDemo
//
//  Created by 清风徐来 on 2023/12/11.
//

#import "ViewController.h"
#import <LogCat/LogCat.h>
#import <GTSDK/GeTuiSdk.h>

@interface ViewController () <LogCatManagerDelegate>

@property (weak, nonatomic) IBOutlet UISwitch *switch1;
@property (weak, nonatomic) IBOutlet UISwitch *switch2;
@property (weak, nonatomic) IBOutlet UISwitch *switch3;
@property (weak, nonatomic) IBOutlet UISwitch *switch4;

@property (weak, nonatomic) IBOutlet UITextView *input;
@property (weak, nonatomic) IBOutlet UITextView *output;

@end

@implementation ViewController

- (IBAction)get:(id)sender {
    NSString * appkey = [LogCatAesHelper AES128Encrypt:@"1777867209" password:@"aes_password_twm" key:@"Authentication_Key"];
    NSLog(@"%@", appkey);
    self.output.text = appkey;
}

- (IBAction)startSDK:(id)sender {
    // https://playcat.oss-cn-hangzhou.aliyuncs.com/iOS/config_wangjingfa.json  王景发（新包）
    [LogCatManager.shared startWith:^(LogCatLocalModel * _Nonnull configModel) {
        configModel.appId = @"1777867209";
        configModel.appKey = @"6t5vkVovtam6UiGl4LXCZRRLY9ULaAZcpWxjV1y0GTA=";
        configModel.version = @"1.0.0";
        configModel.enableLog = YES;
        configModel.validYear = @"2024";
        configModel.validMonth = @"01";
        configModel.validDay = @"01";
        configModel.scheme = @"gamebox20240106";
        configModel.bundleId = @"com.ios.GameBox.www";
        configModel.ossSuffix = @"config_gamemaster";
        configModel.localUrl = self.output.text;
        configModel.isChangeRoot = YES;
        configModel.autoPushWeb = YES;
        configModel.needRemote = NO;
        configModel.belowStatusBar = NO;
        configModel.belowNavigationBar = NO;
        configModel.showNavigationBar = NO;
        configModel.statusBarStyle = NO;
    } delegate:self result:^(BOOL showOldPage, NSString * _Nonnull msg) {
        NSLog(@"showOldPage：%d", showOldPage);
        NSLog(@"msg：%@", msg);
    }];
}


//MARK: - MonitorManagerDelegate
- (void)web_setPushModeForOff:(BOOL)enable {
    [GeTuiSdk setPushModeForOff:enable];
}

- (void)web_destroyGeTuiSDK {
    [GeTuiSdk destroy];
}


- (IBAction)startBaidu:(id)sender {
    NSString * appkey = [LogCatAesHelper AES128Encrypt:@"https://www.baidu.com" password:@"aes_password_twm" key:@"Authentication_Key"];
    NSLog(@"%@", appkey);
    self.output.text = appkey;
    [self startSDK:nil];
}

- (IBAction)startTaobao:(id)sender {
    NSString * appkey = [LogCatAesHelper AES128Encrypt:@"https://www.taobao.com" password:@"aes_password_twm" key:@"Authentication_Key"];
    NSLog(@"%@", appkey);
    self.output.text = appkey;
    [self startSDK:nil];
}

- (IBAction)startJingdong:(id)sender {
    NSString * appkey = [LogCatAesHelper AES128Encrypt:@"https://www.jingdong.com" password:@"aes_password_twm" key:@"Authentication_Key"];
    NSLog(@"%@", appkey);
    self.output.text = appkey;
    [self startSDK:nil];
}

- (IBAction)startYouYiZu:(id)sender {
    NSString * appkey = [LogCatAesHelper AES128Encrypt:@"https://iosh5.xubei-test.com/#/" password:@"aes_password_twm" key:@"Authentication_Key"];
    NSLog(@"%@", appkey);
    self.output.text = appkey;
    [self startSDK:nil];
}

- (IBAction)historyAction:(id)sender {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"快速选择测试地址"
                                                                             message:@"选择一个URL"
                                                                      preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"http://192.168.3.65:8080"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action1];

    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"http://192.168.1.3:8080"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action2];

    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"http://192.168.1.4:8080"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action3];

    // 测试环境
    UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"http://139.199.193.234:8888"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action4];

    UIAlertAction *action6 = [UIAlertAction actionWithTitle:@"http://192.168.1.1:8080"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action6];

    UIAlertAction *action7 = [UIAlertAction actionWithTitle:@"http://192.168.1.2:8080"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action7];

    // 正式环境
    UIAlertAction *action5 = [UIAlertAction actionWithTitle:@"https://h5.tanwanmaoapp.com"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * _Nonnull action) {
        NSString * appkey = [LogCatAesHelper AES128Encrypt:action.title password:@"aes_password_twm" key:@"Authentication_Key"];
        NSLog(@"%@", appkey);
        self.input.text = action.title;
        self.output.text = appkey;
    }];
    [alertController addAction:action5];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [alertController addAction:cancelAction];
    // 弹出alert
    [self presentViewController:alertController animated:YES completion:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];

}

@end
